﻿//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using EntLibContrib.Query.Commands;

namespace EntLibContrib.Query.QuickStart.CustomCommands
{
	/// <summary>
	/// Custom data command to read a set of active Basic1 objects sorted in SampleString order
	/// </summary>
	public class ReadBasic1ObjectSortCommand : DataCommand
	{
		#region Constants
		private const string commandText = "select b.* from [Query].[Domain].[Basic1] as b inner join [QueryAudit].[Standard].[Audit] as a on b.Id = a.PrimaryId where (a.DeletedDate is null) order by SampleString";
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="ReadBasic1ObjectSortCommand"/> class.
		/// </summary>
		public ReadBasic1ObjectSortCommand()
		{
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Executes a read action.
		/// </summary>
		/// <returns>
		/// a DataSet containing the results of the read action
		/// </returns>
		public override DataSet ExecuteForRead()
		{
			// read the xml document
			DbCommand dbCommand = Database.GetSqlStringCommand(commandText);
			//return the dataset
			return Database.ExecuteDataSet(dbCommand);
		}

		/// <summary>
		/// Executes a write action.
		/// </summary>
		public override void ExecuteForWrite()
		{
			throw new NotImplementedException();
		}
		#endregion
	}
}
